package com.demos.springcloud.gateway02RouteBean.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RouteConfig {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder routeLocatorBuilder){
        System.out.println("============== routeBean ==============");
        //会把application.yml中相同的配置冲掉
        return routeLocatorBuilder
                .routes()
                .route("way1", predicateSpec -> predicateSpec
                        .host("*host*").and()
                        .path("/get/**")
                        .uri("lb://getprovider"))
                .route("way2", predicateSpec -> predicateSpec
                        .path("/post/**")
                        .uri("lb://postprovider"))
                .build();
    }

}
